<?php
declare(strict_types=1);

namespace App\Enum;

enum Code: int
{
    case OK = 200;
    case RequestParamError = 40001;

    case ValidationError = 40002;

    case Unauthorized = 40101;

    case TokenExpired = 40102;

    case PermissionDenied = 40301;

    case ResourceNotFound = 40401;

    case RequestTooMany = 42901;

    case InternalServerError = 50001;

    case SignedToday = 10001;

    case ArticleNotFound = 10002;

    public function getHttpCode(): int
    {
        return match ($this) {
            self::OK => 200,
            self::RequestParamError, self::SignedToday, self::ValidationError => 400,
            self::Unauthorized, self::TokenExpired => 401,
            self::PermissionDenied => 403,
            self::ResourceNotFound, self::ArticleNotFound => 404,
            self::RequestTooMany => 429,
            self::InternalServerError => 500,
        };
    }
}